<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>报告模板</title>
</head>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=IENn7ABARjQIkTeAKyh80VTkg2jYXf3K"></script>

<body>


<div class="x-nav" style="margin: 20px auto auto 15px;">
      <!--<span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">-->
        <!--<a href="javascript:">首页</a><span lay-separator="">/</span>-->
        <!--<a href="javascript:">报告模板</a>-->
      <!--</span>-->
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
</div>


<div class="layui-fluid">
    <div class="layui-card">
        <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
        <script type="text/html" id="toolbarDemo">
            <a class="layui-btn layui-btn layui-btn-sm" >通知列表信息</a>
        </script>
        <script type="text/html" id="table-useradmin-webuser">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>查看</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
    </div>
</div>
<!-- 弹出页面 -->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
    <form action class="layui-form" lay-filter="component-form-element" id="myform">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" class="layui-input" >
                <input type="text" name="title" lay-verify="required" readonly autocomplete="off" placeholder="请输入标题.." class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea name="content" lay-verify="required" readonly placeholder="请输入内容..." class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发布者</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" readonly autocomplete="off" placeholder="发布者" class="layui-input">
            </div>
        </div>
    </form>
</div>


<!-- 弹出查看页面 -->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin1"
     style="padding: 15px;display: none">
    <form action class="layui-form" lay-filter="component-form-element1" id="myform1">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" class="layui-input" >
                <input type="text" name="title" lay-verify="required" readonly autocomplete="off" placeholder="请输入标题.." class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea name="content" lay-verify="required" readonly placeholder="请输入内容..." class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发送人</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" readonly autocomplete="off" placeholder="发送人" class="layui-input">
            </div>
        </div>

    </form>
</div>
<%include("/common/foot.html"){}%>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-gl/dist/echarts-gl.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-stat/dist/ecStat.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/extension/dataTool.min.js"></script>
<script>
    layui.use(['index', 'table', 'form', 'laydate', 'layedit', 'AjaxCommon', 'AliangLayui'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var AjaxCommon = layui.AjaxCommon;
        var AliangLayui = layui.AliangLayui;

        var title = "通知列表";
        var size = ["700px","500px"];
        var findAll_url='notice/myFindAll.json';
        var update_url='temp/update.jhtml';
        var delete_url='notice/delete.jhtml';

        var cols = [ //表头
            {checkbox: true,fixed:true},
            {field: 'title',   title: '标题'},
            {field: 'name',   title: '发送人'},
            {field: 'time', templet:"<div>{{layui.util.toDateString(d.time, 'yyyy-MM-dd HH:mm:ss')}}</div>",title: '发布时间'},
            {title:'操作', width:147, toolbar: '#table-useradmin-webuser',fixed:'right'}
        ];
        table.render({
            elem: '#LAY-user-manage',
            id: 'listReload',
            toolbar: '#toolbarDemo',
            title: title,
            url: findAll_url,
            page: true, //开启分页
            limits: [10, 20, 30, 50], //控制多少行一页（默认五条一页）
            defaultToolbar: ['filter', 'print', 'exports'],
            cols: [cols],
            done() {
                //alert() 数据渲染完的方法
            }
        });

        // laydate.render({
        //     elem: '#start',
        // });
        // laydate.render({
        //     elem: '#end'//指定元素
        // });

        //自定义验证规则
        form.verify({
            required : [ /[\S]+/, "必填项不能为空" ],

        });

        //初始化修改页面
        function loadData(data){
            var ret={
                "id": data.id,
                "title": data.title,
                "content": data.content,
                "name": data.name

            };
            $("#tb").html(data.content);
            //$("#ym").text(data.content);

            return ret;
        }




        //初始化日期模块
        laydate.render({
            elem: '#create' //指定元素
        });
        //////////////////////////////////////以上是修改每个页面修改的地方
        //弹出修改页面调用初始化数据方法
        function initUpdate(data){
            //alert(data.id);
            //table.reload('listReload');
            layer.open({
                title: title,
                area: size,
                type: 1,
                content: $('#layuiadmin-form-useradmin'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                btn: ['关闭'] //可以无限个按钮
            });
            if(data==0 || data==null){
                //$(":reset").click()
                $('#myform')[0].reset();
                return;
            }
            layui.form.val("component-form-element",loadData(data));
        }
        //修改页面的内容提交到后台处理
        form.on('submit(component-form-element)', function(data){
            postUpdate(data);
            return false;
        });
        //头工具栏事件
        table.on('toolbar(LAY-user-manage)', function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    initUpdate(0);
                    break;
                case 'delete':
                    var data = checkStatus.data;
                    if (data.length > 0) {
                        //var id = new Array(); //声明数组
                        for (var i in data) {
                            var a = data[i].id;//得到复选框的值
                            postDelete(a);
                        }
                        /*layer.confirm('删除以后数据将不能恢复，确定删除吗？', function(index) {
                            //alert(data.id);
                            postDelete(id);
                        });*/
                        //alert(id)
                        //layer.alert(JSON.stringify(data));
                        //layer.close(index);
                    } else {
                        layer.msg("至少选择一个进行删除");
                    }
                    break;
                case 'export':
                    layer.msg("导出");
                    break;
            }
        });










        //点击每行右工具栏“操作”里面按钮效果
        table.on('tool(LAY-user-manage)', function(obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'edit') {
                initUpdate(data);
            } else if (obj.event === 'del') {
                layer.confirm('删除以后数据将不能恢复，确定删除吗？', function(index) {
                    //alert(data.id);
                    postDelete(data.id);
                });
            }
        });


        //监听搜索按钮效果
        form.on('submit(LAY-user-front-search)', function(data) {
            var field = data.field;
            table.reload('listReload', {
                where :{
                    name: field.name,
                    price: field.price,
                    pay: field.pay
                },
                page: {
                    curr: 1
                }
            });
        });

        //ajax提交删除内容
        window.postDelete = function (id){
            $.ajax({
                url : delete_url,
                type : "POST",
                data : {
                    "id" : id
                },
                dataType : "json",
                success : function(ret) {
                    if (ret == null) {
                        layer.msg("删除失败", {
                            icon : 5
                        });
                    } else {
                        layer.msg("删除成功", {
                            icon : 6
                        });
                        layer.closeAll();
                        table.reload('listReload');
                    }
                    return ret;
                },
                error:function(jqXHR, textStatus, errorThrown){
                    var estr="Page:"+window.location.pathname+",Function: postDelete()";
                    layer.open({
                        title: "错误信息",
                        area: ['600px', '600px'],
                        type: 2,
                        content: "base/error.jhtml?info="+estr, //
                        btn: ['关闭'] //可以无限个按钮
                    });
                }
            });
        };

        //ajax提交修改内容
        window.postUpdate = function (data){
            var formData = new FormData();
            // 利用append的内置方式
            formData.append("data", JSON.stringify(data.field));

            $.ajax({
                url: update_url,
                type: "POST",
                //traditional:true,
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 0) {
                        layer.closeAll();
                        layer.msg(data.msg, {time: 600, icon: 1}, function () {
                            //table.reload('listReload');

                        });
                        location.replace(location.href);
                    } else {
                        layer.msg(data.msg, {icon: 6});
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    var estr="Page:"+window.location.pathname+",Function:postUpdate()";
                    layer.open({
                        title: "错误信息",
                        type: 2,
                        content:  "base/error.jhtml?info="+estr,
                        btn: ['关闭'] //可以无限个按钮
                    });
                }
            });
        }
    });


</script>


</body>

</html>
